<template>
  <div class="progress-bar-container" :style="{ width: `${width}px` }">
    <div class="progress-bar-bg">
      <div 
        class="progress-bar-fill" 
        :style="{ 
          width: `${Math.min(100, Math.max(0, progress))}%`,
          backgroundColor: progressColor,
          backgroundImage: progress >= 20 ? 'linear-gradient(45deg, rgba(255,255,255,0.2) 25%, transparent 25%, transparent 50%, rgba(255,255,255,0.2) 50%, rgba(255,255,255,0.2) 75%, transparent 75%, transparent)' : 'none',
          backgroundSize: '8px 8px'
        }"
      >
        <span class="progress-text">{{ Math.round(progress) }}%</span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue';

interface Props {
  progress: number;
  width?: number;
}

const props = withDefaults(defineProps<Props>(), {
  width: 120
});

const progressColor = computed(() => {
  const progress = Math.min(100, Math.max(0, props.progress));
  
  if (progress >= 100) return '#67C23A'; // 绿色 - 完成
  if (progress >= 80) return '#409EFF';  // 蓝色 - 80-99
  if (progress >= 50) return '#E6A23C';  // 橙色 - 50-79
  if (progress >= 20) return '#F56C6C';  // 红色 - 20-49
  return '#909399'; // 灰色 - 0-19
});
</script>

<style scoped lang="scss">
.progress-bar-container {
  position: relative;
  height: 16px;
}

.progress-bar-bg {
  width: 100%;
  height: 100%;
  background-color: #f0f0f0;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 8px;
  transition: all 0.3s ease;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: progress-stripes 1s linear infinite;
}

@keyframes progress-stripes {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 16px 0;
  }
}

.progress-text {
  color: white;
  font-size: 11px;
  font-weight: bold;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
  z-index: 1;
}
</style>
